function output = lab2lloyds(inImg,levels)

[partition, codebook] = lloyds(double(inImg(:)), levels);
output = zeros(size(inImg));
partition = [-inf partition inf];

for i=1:length(partition)-1
    mask = inImg > partition(i) & inImg < partition(i+1);
    output(mask) = codebook(i);
end

end